import React, { Component } from 'react'

import { HashRouter as Router, Route, Redirect, Switch } from 'react-router-dom'

import routesMap from '../router/routesMap'

import asyncComponent from '@/components/AsyncComponent'


const routes = [
    /**
     * 首页
     */
    {
        path: routesMap.home,
        component: asyncComponent(() => import('@/routes/Home')),
    },
    // 最新音乐排行榜top100
    {
        path: routesMap.rankingList,
        component: asyncComponent(() => import('@/routes/RankingList')),
    },
    // 随机推荐
    {
        path: routesMap.randomRecommen,
        component: asyncComponent(() => import('@/routes/RandomRecommen')),
    },
]

export default class Layout extends Component {
    render() {
        return (<React.Fragment>

            <Router>

                <Switch>
                    <Redirect exact path="/" to={routesMap.home}></Redirect>

                    {routes.map(
                        (route, idx) => {
                            const { auth, exact, ...rest } = route
                            return (
                                <Route
                                    {...rest}
                                    {...this.props}
                                    exact
                                    key={idx}
                                />
                            )
                        }
                    )}
                </Switch>

            </Router>

        </React.Fragment>)
    }
}